/**
 * 
 */
package com.apache.website.service.plugins;

import com.apache.api.manager.PluginConnector;
import com.apache.api.vo.ParamsVo;
import com.apache.api.vo.ResultEntity;
import com.apache.database.constant.Validator;
import com.apache.website.entity.Channel;
import com.apache.website.manager.ChannelManager;

/**
 * @author dyhou
 *
 */
public class ChannelEntityPluginImpl implements PluginConnector {

	private ChannelManager channelManager;

	/* (non-Javadoc)
	 * @see com.apache.api.manager.PluginConnector#execute(com.apache.api.vo.ParamsVo)
	 */
	public Object execute(ParamsVo param) throws Exception {
		String channelId = String.valueOf(param.getParams("channelId"));
		String codeName = String.valueOf(param.getParams("codeName"));
		codeName = Validator.getDefaultStr(codeName, String.valueOf(param.getParams("channelCode")));
		ResultEntity entity = new ResultEntity();//channelCode
		if (Validator.isNull(channelId) && Validator.isNull(codeName)) {
			entity.setResult("false");
			entity.setMessage("缺少必要参数");
			return entity;
		}
		ParamsVo<Channel> cvo = new ParamsVo<Channel>();
		Channel channel = new Channel();
		if (Validator.isNotNull(channelId)) {
			cvo.setInfoId(channelId);
			channel = (Channel) channelManager.getInfoById(cvo);
		} else {
			cvo.setKey("ByCodeName");
			cvo.setParams("codeName", codeName);
			channel = (Channel) channelManager.execute(cvo);
		}
		//
		entity.setResult("true");
		entity.setEntity(channel);
		entity.setMessage("查询成功");
		return entity;
	}

	public void setChannelManager(ChannelManager channelManager) {
		this.channelManager = channelManager;
	}

}
